package org.jeecg.modules.wlhy.customer.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.entity.HyDfFee;
import org.jeecg.modules.wlhy.customer.service.IHyDfFeeService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.wlhy.utils.UserUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: hy_df_fee
 * @Author: jeecg-boot
 * @Date:   2023-01-10
 * @Version: V1.0
 */
@Api(tags="hy_df_fee")
@RestController
@RequestMapping("/customer/hyDfFee")
@Slf4j
public class HyDfFeeController extends JeecgController<HyDfFee, IHyDfFeeService> {
	 @Autowired
	 private IHyDfFeeService hyDfFeeService;

	 @Autowired
	 private UserUtil userUtil;

	 @ApiOperation(value = "hy_df_fee-分页列表查询", notes = "hy_df_fee-分页列表查询")
	 @GetMapping(value = "/list")
	 public Result<?> queryPageList(HyDfFee hyDfFee,
									@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
									@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
									HttpServletRequest req) {
		 HyCustomer customer = userUtil.getCustomer();
		 if (customer == null) {
			 return Result.error("货主信息不存在");
		 }
		 QueryWrapper<HyDfFee> queryWrapper = QueryGenerator.initQueryWrapper(hyDfFee, req.getParameterMap());
		 queryWrapper.eq("agent_id", customer.getId());
		 Page<HyDfFee> page = new Page<HyDfFee>(pageNo, pageSize);
		 IPage<HyDfFee> pageList = hyDfFeeService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 @AutoLog(value = "hy_platform_cost-还款")
	 @ApiOperation(value="hy_platform_cost-还款", notes="hy_platform_cost-还款")
	 @PutMapping(value = "/hk")
	 public Result<?> hk(@RequestParam(name="id",required=true) String id) {
		 HyCustomer customer = userUtil.getCustomer();
		 if (customer == null) {
			 return Result.error("货主信息不存在");
		 }
		 HyDfFee dfFee = hyDfFeeService.getById(id);
		 if(dfFee == null){
			 return Result.error("数据不存在");
		 }
		 if(!StringUtils.equals(dfFee.getAgentId(),customer.getId())){
			 return Result.error("数据错误");
		 }
		 if("1".equals(dfFee.getSt())){
			 return Result.error("已完成还款，不能重复操作");
		 }
		 dfFee.setSt("1");
		 hyDfFeeService.updateById(dfFee);
		 return Result.OK("操作成功");
	 }

/*    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HyDfFee hyDfFee) {
        return super.exportXls(request, hyDfFee, HyDfFee.class, "hy_df_fee");
    }*/

 }
